<?php

class DateComponent extends Object {

	function startup(&$controller) {
		$this->Controller = &$controller;
	}
	
	function minutesToDatetime($minutes) {
		
		return date('d-m-Y H:i', $minutes * 60);
	}
	
	function minutesToDate($minutes) {
		
		return date('d-m-Y', $minutes * 60);
	}
	
	function minutesToTime($minutes) {
		
		$hours = floor($minutes/60);
		$minutes = $minutes % 60;

		$hours = (strlen($hours) == 1) ? '0'.$hours : $hours;
		$minutes = (strlen($minutes) == 1) ? '0'.$minutes : $minutes;
		
		return $hours . ':' . $minutes;
	}
	
	/*
	 * $date format: DD-MM-YYYY HH:MM
	 */
	function dateToMinutes($date) {
		return (floor(strtotime($date) / 60)).'';
	}
	
	/*
	 * $time format HH:MM
	 */
	function timeToMinutes($time) {
		$time = explode(':', $time);
		return $time[0] * 60 + $time[1];
	}
}

?>
